package com.springboot.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.springboot.cloud.entities.Article;
import com.springboot.cloud.feignservice.ArticleFeignService;

@RestController
public class ArticleController {

	@Autowired
	private ArticleFeignService articleFeignService;
	
	@ResponseBody
	@RequestMapping(value = "/geta/{start}", method = RequestMethod.GET)
	public List<Article> geta(@PathVariable("start") int start) {
		return articleFeignService.geta(start);
	}
	@ResponseBody
	@RequestMapping(value = "/getone/{id}", method = RequestMethod.GET)
	public Article getone(@PathVariable("id") int id) {
		return articleFeignService.getone(id);
	}
	@ResponseBody
	@RequestMapping(value = "/getmyarticle/{uid}", method = RequestMethod.GET)
	public List<Article> getmyarticle(@PathVariable("uid") int uid) {
		return articleFeignService.getmyarticle(uid);
	}
	
	@RequestMapping(value = "/addfavorite/{id}/{aid}", method = RequestMethod.GET)
	public boolean addfavorite(@PathVariable("id") int id,@PathVariable("aid") int aid) {
		return articleFeignService.addfavorite(id,aid);
	}
	@ResponseBody
	@RequestMapping(value = "/getfavorite/{id}", method = RequestMethod.GET)
	public List<Article> getfavorite(@PathVariable("id") int id) {
		return articleFeignService.getfavorite(id);
	}

	@RequestMapping(value = "/adda", method = RequestMethod.POST)
	public Object adda(@RequestBody Article a) {
		System.out.println(a.toString());
		return articleFeignService.adda(a);
	}
	
	@RequestMapping(value = "/addlike/{id}", method = RequestMethod.GET)
	public boolean addlike(@PathVariable("id") int id) {
		return articleFeignService.addlike(id);
	}
	@RequestMapping(value = "/addnolike/{id}", method = RequestMethod.GET)
	public boolean addnolike(@PathVariable("id") int id) {
		return articleFeignService.addnolike(id);
	}
	
}
